/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.tb_out_car_register.service;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.common.utils.IdGen;
import com.thinkgem.jeesite.modules.sys.entity.User;
import com.thinkgem.jeesite.modules.sys.utils.UserUtils;
import com.thinkgem.jeesite.modules.tb_out_car_register.dao.TbOutCarRegisterDao;
import com.thinkgem.jeesite.modules.tb_out_car_register.entity.TbOutCarRegister;
import com.thinkgem.jeesite.modules.tb_waybill.dao.TbWaybillDao;
import com.thinkgem.jeesite.modules.tb_waybill.entity.TbWaybill;

/**
 * 出车登记Service
 * @author ZhangYangZe
 * @version 2017-06-03
 */
@Service
@Transactional(readOnly = true)
public class TbOutCarRegisterService extends CrudService<TbOutCarRegisterDao, TbOutCarRegister> {

	@Autowired
	private TbWaybillDao tbWaybillDao;
	
	public TbOutCarRegister get(String id) {
		return super.get(id);
	}
	
	public List<TbOutCarRegister> findList(TbOutCarRegister tbOutCarRegister) {
		return super.findList(tbOutCarRegister);
	}
	
	public Page<TbOutCarRegister> findPage(Page<TbOutCarRegister> page, TbOutCarRegister tbOutCarRegister) {
		return super.findPage(page, tbOutCarRegister);
	}
	
	@Transactional(readOnly = false)
	public void save(TbOutCarRegister tbOutCarRegister) {
		super.save(tbOutCarRegister);
	}
	@Transactional(readOnly = false)
	public void saveNew(TbOutCarRegister tbOutCarRegister) {
		User user = UserUtils.getUser();
		tbOutCarRegister.setCreateBy(user);
		tbOutCarRegister.setUpdateBy(user);
		Date date = new Date();
		tbOutCarRegister.setCreateDate(date);
		tbOutCarRegister.setUpdateDate(date);
		tbOutCarRegister.setId(IdGen.uuid());
		dao.insert(tbOutCarRegister);
		TbWaybill tbWaybill = new TbWaybill();
		tbWaybill.setId(tbOutCarRegister.getWaybillId());
		tbWaybill.setRegisterState("2");
		tbWaybill.setUpdateBy(user);
		tbWaybillDao.updateNew(tbWaybill);
	}
	
	
	@Transactional(readOnly = false)
	public void delete(TbOutCarRegister tbOutCarRegister) {
		super.delete(tbOutCarRegister);
	}
	/**
	 * 以运单号查询出车登记列表 
	 * @param String
	 * @return List<TbOutCarRegister>
	 */
	public List<TbOutCarRegister> selectOutCarRegister(List<String> waybillId){
		return dao.selectOutCarRegister(waybillId);
	}
}